package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.OrderItem;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.OrderItemServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 订单明细：支持一个订单多商品/食品Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/item")
public class OrderItemController
{

    @Autowired
    private OrderItemServiceImpl orderItemService;


    /**
     * 查询订单明细：支持一个订单多商品/食品列表
     */

    @GetMapping("/page")
    @ResponseBody
    public R<Page<OrderItem>> selectPage(@ParameterObject Page page,@ParameterObject OrderItem orderItem)
    {
        Page<OrderItem> page1 = orderItemService.selectOrderItemList(page, orderItem);
        if(page1==null) return R.failed();
        return R.ok(page1);
    }

    /**
     * 导出订单明细：支持一个订单多商品/食品列表
     */


    /**
     * 新增保存订单明细：支持一个订单多商品/食品
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody OrderItem orderItem)
    {
        int flag=orderItemService.insertOrderItem(orderItem);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }

    /**
     * 修改订单明细：支持一个订单多商品/食品
     */

    @GetMapping("/get/{id}")
    public R<OrderItem> getById(@PathVariable("id") Long id)
    {
        OrderItem orderItem = orderItemService.selectOrderItemById(id);
        if(orderItem==null) return R.failed();
        return R.ok(orderItem);
    }

    /**
     * 修改保存订单明细：支持一个订单多商品/食品
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody OrderItem orderItem)
    {
        int flag=orderItemService.updateOrderItem(orderItem);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }

    /**
     * 删除订单明细：支持一个订单多商品/食品
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int flag=orderItemService.deleteOrderItemById(id);
        if(flag==0) return R.failed();
        return R.ok(flag);
    }
}
